package utils

import (
	"context"

	"github.com/cloudwego/hertz/pkg/app"
)

// SendErrResponse  pack error response
func SendErrResponse(ctx context.Context, c *app.RequestContext, code int, err error) {
	// todo edit custom code
	errResp := ErrResponse{}
	errResp.Code = code
	errResp.Message = err.Error()
	errResp.Data = err
	errResp.Success = false
	c.JSON(500, errResp)
}

// SendSuccessResponse  pack success response
func SendSuccessResponse(ctx context.Context, c *app.RequestContext, code int, data interface{}) {
	// todo edit custom code
	successResp := SuccessResponse{}
	successResp.Code = code
	successResp.Message = "success"
	successResp.Data = data
	successResp.Success = true
	c.JSON(200, successResp)
}

// ErrResponse pack error response
type ErrResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Success bool        `json:"success"`
}

func NewErrResponse(code int, message string, data interface{}) *ErrResponse {
	return &ErrResponse{
		Code:    code,
		Message: message,
		Data:    data,
		Success: false,
	}
}

type SuccessResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
	Success bool        `json:"success"`
}

func NewSuccessResponse(code int, message string, data interface{}) *SuccessResponse {
	return &SuccessResponse{
		Code:    code,
		Message: message,
		Data:    data,
		Success: true,
	}
}
